home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
CRS
/
crs54.d81
/
trans12c.lbr
/
TRANS128.PAS
< prev
Wrap
Pascal/Delphi Source File
|
2009-10-10
|
12KB
|
438 lines
(*********************************************************)
(* *)
(* TRANSFER.PAS (version 1.0) - *)
(* a program to transfer files between cp/m and ms-dos *)
(* with a cp/m host system *)
(* *)
(* Written by David Koski 1985 *)
(* P.O. Box 1078 *)
(* Fort Bragg, CA 95437-1078 *)
(* 707/964-0806 *)
(* *)
(* This program is intended for private non-commercial *)
(* use and is considered to be public domain material *)
(* *)
(*********************************************************)
(* *)
(* TRANS128.PAS (version 1.2C) - *)
(* Modified/enhanced for C-128 with single 1571 drive: *)
(* Format MS-DOS disks, *)
(* Rename MS-DOS files, *)
(* View MS-DOS text files. *)
(* *)
(* by B-J Lee 1987 *)
(* 1021 Merritt Dr. *)
(* Tallahassee, FL 32301 *)
(* CompuServe [71171,3260] *)
(* *)
(*********************************************************)
program Transfer;
const
SecTrans = false; { sector translation for bios read/write }
SO = 0; { offset added to sector number }
DEBUG = false;
DataBufferSize = 30720; { 30 K bytes }
MinSector = 0;
MaxFATSize = 1024;
Vers = '1.2C';
SectorSizeMax = 512;
BufferSize = SectorSizeMax;
MenuMargin = 18;
{ClusterSizeMax = 2048;}
SizePC_FCB = 32;
SizeCPM_FCB = 32;
NameSize = 8;
TypeSize = 3;
First = true;
Next = false;
EODirectory = $FF;
MTDirectory = 1;
FoundDir = 0;
SELDSK = 9; { BIOS calls for CP/M+ }
SETTRK = 10;
SETSEC = 11;
SETDMA = 12;
RDSEC = 13;
WRSEC = 14;
SECTRAN = 16;
DEVTBL = 20;
DRVTBL = 22;
FLUSH = 24;
USERFUN = 30;
GETVSN = 12; { BDOS calls }
RESETDSK = 13;
LOGDSK = 14;
SearchF = 17;
SearchN = 18;
CURDSK = 25;
SetDMAF = 26;
SETATT = 30;
COMPUTESIZE = 35;
CALLBIOS = 50;
type
SizeArray= Array[1..4] of Byte;
Str20 = string[20];
Bufr = array[1..BufferSize] of char;
{CBufr = array[1..ClusterSizeMax] of char;}
FATarray = array[1..MaxFATSize] of byte;
FAT_ID = (Unidentified,ss8spt,ds8spt,ss9spt,ds9spt,B_20);
NameAry = array[1..NameSize] of char;
TypeAry = array[1..TypeSize] of char;
NameStr = string[20];
PC_FCB = record
Name: NameAry;
Extention: TypeAry;
Attribute: byte;
Rsrvd: array[12..21] of byte;
Time: integer;
Date: integer;
ClusterNo: integer;
FileSize: SizeArray;
end;
CpmFCB = record
DriveCode: byte; {0=default, 1=A, 2=B...}
Name: NameAry;
Extention: TypeAry;
Extent: byte;
S1,S2: byte;
RC: byte;
Rsrvd: array[16..31] of byte;
CR: byte;
R0,R1,R2: byte;
end;
var
CPMversion: integer;
CPM_Buf: array[1..128] of char;
Done: boolean;
Selection: char;
I: integer;
DefaultDisk: integer;
MS_DOS_Drive: integer;
CPM_Drive: integer;
CPM_DriveCh: char;
Track: integer;
Sector: integer;
SecsPerCluster: integer;
FAT: FATarray;
FATSize: integer;
SectorSize: integer;
RecordsPerSector: integer;
DirSecs: integer;
NTracks: integer;
NSectors: integer;
NClusters: integer;
Identity: FAT_ID;
FirstFATSector: integer;
FirstDirSector: integer;
FirstDataSector: integer;
FirstDataTrack: integer;
DirSector: integer;
DirTrack: integer;
DirSectorCount: integer;
SingleSided: boolean;
DOS_FCB: ^PC_FCB;
CPM_FCB: CpmFCB;
Buffer: Bufr;
DirBuffer: Bufr;
DirOffset: integer;
DirName: NameStr;
{ClusterBuffer: CBufr;}
MaxSector: integer;
InFile: File;
CPMFile: File;
BiosError: boolean;
VolumeName: boolean;
SubDirName: boolean;
Stop: boolean;
Wildcard: boolean;
D: integer; {a dummy for function bios3()}
UnusedBytes: integer; {# of unused bytes in the last record}
MFMTablePointer: integer;
BankZeroAddress: integer;
DataBuffer: array[1..DataBufferSize] of char;
BufferIndex: integer;
NumberOfClusters: integer;
ExtraBytes: integer;
type
BiosPB = record
func: byte;
aVal: byte;
bcVal: integer;
deVal: integer;
hlVal: integer;
end;
var
Bios_PB: BiosPB;
function bios3(fn,aReg: byte; bcReg,deReg,hlReg: integer): integer;
begin
if (CPMversion < $30) then
begin
case fn of
9,16,20,22: bios3 := bioshl(fn-1, bcReg);
else bios3 := bios(fn-1, bcReg);
end;
end
else
begin
with Bios_PB do
begin
fillchar(Bios_PB, 8, 0);
func := fn;
aVal := aReg;
bcVal := bcReg;
deVal := deReg;
hlVal := hlReg;
case fn of
9,16,20,22: bios3 := bdoshl(CALLBIOS, addr(Bios_PB));
else bios3 := bdos(CALLBIOS, addr(Bios_PB));
end;
end;
end;
end;
type
MFMEntry = record
classification: byte;
format: byte;
xlt: integer;
spt: integer;
bsh: byte;
blm: byte;
exm: byte;
dsm: integer;
drm: integer;
al0: byte;
al1: byte;
cks: integer;
off: integer;
psh: byte;
phm: byte;
pspt: byte;
DiskType: array[1..10] of char;
end;
const
MS_DOSType: array[0..3] of MFMEntry =
((classification:$49; format:$A3; xlt:0; spt:$20; bsh:3; blm:7;
exm:0; dsm:$13F; drm:$6F; al0:$C0; al1:0; cks:$10;
off:0; psh:2; phm:3; pspt:8; diskType:'MSDOS-1 DS'),
(classification:$49; format:$A5; xlt:0; spt:$20; bsh:3; blm:7;
exm:0; dsm:$9F; drm:$3F; al0:$C0; al1:0; cks:$10;
off:0; psh:2; phm:3; pspt:8; diskType:'MSDOS-1 SS'),
(classification:$4B; format:$A3; xlt:0; spt:$24; bsh:3; blm:7;
exm:0; dsm:$167; drm:$6F; al0:$C0; al1:0; cks:$10;
off:0; psh:2; phm:3; pspt:9; diskType:'MSDOS-2 DS'),
(classification:$4B; format:$A5; xlt:0; spt:$24; bsh:3; blm:7;
exm:0; dsm:$B3; drm:$3F; al0:$C0; al1:0; cks:$10;
off:0; psh:2; phm:3; pspt:9; diskType:'MSDOS-2 SS'));
procedure LoadMFMTable(EntryIndex, EntryAddress: integer);
var
I: integer;
begin
BankZeroAddress := MFMTablePointer + (EntryIndex * 32);
for I := 0 to 31 do
D := bios3(USERFUN, 1, mem[EntryAddress + I], BankZeroAddress + I, 0);
end;
procedure CheckWildcard(Filename: Str20);
begin
Wildcard := false;
if (pos('*', Filename) > 0) then Wildcard := true;
end;
{$I TRANS-01.INC}
{$I TRANS-02.INC}
{$I TRANS-03.INC}
{$I TRANS-04.INC}
{$I TRANS-05.INC}
{$I TRANS-06.INC}
procedure EraseMS_DOS; {or rename MS-DOS file}
var
FileName: Str20;
NextCl,I,Err: integer;
Cl: integer;
begin
IdentifyMS_DOS;
if not (Identity = Unidentified) then
begin
ClrScr;
writeln;
if (Selection = '6') then
write('File Name to Erase From MS-DOS: ')
else
write('Old File Name on MS-DOS: ');
readln(FileName);
if (Length(FileName) = 0) then
exit;
writeln;
Stop:= false;
CheckWildcard(FileName);
SearchFirst(FileName,Err);
if (Err = EODirectory) then
begin
write('File Not Found, ');
end
else
begin
if (Selection = '8') then
begin
if (pos('*', FileName) <> 0) or (pos('?', FileName) <> 0) then
exit;
repeat
Stop := false;
write('New File Name (<CR> to abort): ');
readln(FileName);
if (Length(FileName) = 0) then
exit;
for I := 1 to Length(FileName) do
if not (FileName[I]
in ['$', '%', '+', '-'..'9', 'A'..'Z', '_', 'a'..'z']) then
Stop := true;
until not Stop;
ConvertName(FileName, DOS_FCB^.Name, DOS_FCB^.Extention);
WriteSector(DirSector, DirTrack, addr(DirBuffer));
if (CPMversion < $30) then
bdos(RESETDSK); {to force disk write}
Continue;
exit;
end;
writeln('Erasing -');
repeat
for I:= 1 to NameSize do
if not (DOS_FCB^.Name[I] = ' ') then
write(DOS_FCB^.Name[I]);
write('.');
for I:= 1 to TypeSize do
write(DOS_FCB^.Extention[I]);
writeln;
Cl:= DOS_FCB^.ClusterNo;
if (Cl <= NClusters) then
begin
NextCl:= Cl;
repeat
Cl:= NextCl;
NextCl:= FATPointer(Cl);
SetFATPointer(Cl,0);
until ((NextCl > NClusters) or (NextCl = 0));
end;
DOS_FCB^.Name[1]:= #$E5;
WriteSector(DirSector,DirTrack,addr(DirBuffer));
if Wildcard then
SearchNext(FileName,Err);
Stop:= Break;
until (Err = EODirectory) or Stop or not Wildcard;
PutFAT;
writeln;
writeln;
end;
if Stop then write('Aborted, ');
Continue;
end;
end;
(********************)
(* *)
(* main program *)
(* *)
(********************)
begin
ClrScr;
CPMversion := bdoshl(GETVSN);
DefaultDisk:= bdos(CURDSK); {0=A, 1=B...}
CPM_Drive := DefaultDisk;
repeat
gotoxy(1,5);
write('Which Drive is the MS-DOS Disk in? ');
read(KBD,Selection);
write(upcase(Selection),':');
MS_DOS_Drive:= ord(upcase(Selection)) - ord('A'); {0=A, 1=B...}
writeln;
CPM_DriveCh:= chr(CPM_Drive + ord('A'));
until not ((MS_DOS_Drive < 0) or (MS_DOS_Drive >= 16));
writeln;
Delay(500);
MFMTablePointer := mem[$FD46] + mem[$FD46 + 1] *256;
for I := 0 to 3 do {load MFM table into bank 0}
LoadMFMTable(7 + I, addr(MS_DOSType[I]));
done:= false;
repeat
Selection:= MainSelection;
ClrScr;
case Selection of
'1': WriteMS_DOS;
'0','2': ReadMS_DOS;
'3': DirMS_DOS;
'4': MapMS_DOS;
'5': DirCPM;
'8','6': EraseMS_DOS;
'7': RestoreFAT;
{'8': Done := True;}
'9': FormatMS_DOS;
#27: Done := true;
end; (* case *)
until Done;
bdos(RESETDSK);
bdos(LOGDSK, CPM_Drive);
end.